package com.fdb.efp.limit.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.fdb.efp.limit.service.dao.LmtPrelistHandoverLstDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.limit.service.domain.LmtPrelistHandoverLst;
import com.fdb.efp.limit.service.facade.LmtPrelistHandoverLstService;
import com.fdb.efp.limit.service.vo.LmtPrelistHandoverLstVO;

/**
 * <p>
 * 白名单移交明细表的Service实现类
 * </p>
 * @author szbd
 * @createDate 2018-08-02 15:06:19
 */
@Service("lmtPrelistHandoverLstService")
public class LmtPrelistHandoverLstServiceImpl implements LmtPrelistHandoverLstService, FrameworkService {
    
    private static Logger logger = LoggerFactory.getLogger(LmtPrelistHandoverLstServiceImpl.class);
    
    @Autowired
    private LmtPrelistHandoverLstDao lmtPrelistHandoverLstDao;
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistHandoverLstVO> queryAllOwnerByPage(LmtPrelistHandoverLstVO inLmtPrelistHandoverLstVo) {
        logger.info("查询本人所属的白名单移交明细表记录的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverLstVo));
        if(Objects.isNull(inLmtPrelistHandoverLstVo)){
            return null;
        }
        try {
            List<LmtPrelistHandoverLst> dataList = lmtPrelistHandoverLstDao.queryAllOwnerByPage(inLmtPrelistHandoverLstVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistHandoverLstVO> resultList = new ArrayList<LmtPrelistHandoverLstVO>();
                resultList = (List<LmtPrelistHandoverLstVO>) beansCopy(dataList, LmtPrelistHandoverLstVO.class);
                pageSet(resultList, inLmtPrelistHandoverLstVo);
                return resultList;
            } else {
                logger.info("查询本人所属的白名单移交明细表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本人所属的白名单移交明细表记录发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistHandoverLstVO> queryAllCurrOrgByPage(LmtPrelistHandoverLstVO inLmtPrelistHandoverLstVo) {
        logger.info("查询本机构的白名单移交明细表记录的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverLstVo));
        if(Objects.isNull(inLmtPrelistHandoverLstVo)){
            return null;
        }
        try {
            List<LmtPrelistHandoverLst> dataList = lmtPrelistHandoverLstDao.queryAllCurrOrgByPage(inLmtPrelistHandoverLstVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistHandoverLstVO> resultList = new ArrayList<LmtPrelistHandoverLstVO>();
                resultList = (List<LmtPrelistHandoverLstVO>) beansCopy(dataList, LmtPrelistHandoverLstVO.class);
                pageSet(resultList, inLmtPrelistHandoverLstVo);
                return resultList;
            } else {
                logger.info("查询本机构的白名单移交明细表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本机构的白名单移交明细表记录发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistHandoverLstVO> queryAllCurrDownOrgByPage(LmtPrelistHandoverLstVO inLmtPrelistHandoverLstVo) {
        logger.info("查询本机构及下属机构的白名单移交明细表记录的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverLstVo));
        if(Objects.isNull(inLmtPrelistHandoverLstVo)){
            return null;
        }
        try {
            List<LmtPrelistHandoverLst> dataList = lmtPrelistHandoverLstDao.queryAllCurrDownOrgByPage(inLmtPrelistHandoverLstVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistHandoverLstVO> resultList = new ArrayList<LmtPrelistHandoverLstVO>();
                resultList = (List<LmtPrelistHandoverLstVO>) beansCopy(dataList, LmtPrelistHandoverLstVO.class);
                pageSet(resultList, inLmtPrelistHandoverLstVo);
                return resultList;
            } else {
                logger.info("查询本机构及下属机构的白名单移交明细表记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本机构及下属机构的白名单移交明细表记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public int insertLmtPrelistHandoverLst(LmtPrelistHandoverLstVO inLmtPrelistHandoverLstVo) {
        logger.info("新增白名单移交明细表数据的参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverLstVo));
        if(Objects.isNull(inLmtPrelistHandoverLstVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtPrelistHandoverLst lmtPrelistHandoverLst = new LmtPrelistHandoverLst();
            beanCopy(inLmtPrelistHandoverLstVo, lmtPrelistHandoverLst);
            count = lmtPrelistHandoverLstDao.insertLmtPrelistHandoverLst(lmtPrelistHandoverLst);
        } catch (Exception e) {
            logger.error("新增白名单移交明细表数据发生异常！", e);
            count = -1;
        }
        logger.info("当前新增白名单移交明细表数据条数为：" + count);
        return count;
    }
    
    @Override
    public int deleteLmtPrelistHandoverLstByPk(LmtPrelistHandoverLstVO inLmtPrelistHandoverLstVo) {
        logger.info("删除白名单移交明细表数据的参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverLstVo));
        if(Objects.isNull(inLmtPrelistHandoverLstVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtPrelistHandoverLst lmtPrelistHandoverLst = new LmtPrelistHandoverLst();
            beanCopy(inLmtPrelistHandoverLstVo, lmtPrelistHandoverLst);
            count = lmtPrelistHandoverLstDao.deleteLmtPrelistHandoverLstByPk(lmtPrelistHandoverLst);
        } catch (Exception e) {
            logger.error("删除白名单移交明细表数据发生异常！", e);
            count = -1;
        }
        logger.info("删除的白名单移交明细表数据条数为：" + count);
        return count;
    }
    
    @Override
    public int updateLmtPrelistHandoverLstByPk(LmtPrelistHandoverLstVO inLmtPrelistHandoverLstVo) {
        logger.info("修改白名单移交明细表数据的参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverLstVo));
        if(Objects.isNull(inLmtPrelistHandoverLstVo)){
            return 0;
        }
        int count = 0;
        try {
            LmtPrelistHandoverLst lmtPrelistHandoverLst = new LmtPrelistHandoverLst();
            beanCopy(inLmtPrelistHandoverLstVo, lmtPrelistHandoverLst);
            count = lmtPrelistHandoverLstDao.updateLmtPrelistHandoverLstByPk(lmtPrelistHandoverLst);
        } catch (Exception e) {
            logger.error("修改数据发生异常！", e);
            count = -1;
        }
        logger.info("修改的白名单移交明细表数据条数为" + count);
        return count;
    }
    
    @Override
    public LmtPrelistHandoverLstVO queryLmtPrelistHandoverLstByPk(LmtPrelistHandoverLstVO inLmtPrelistHandoverLstVo) {
        logger.info("根据主键查询白名单移交明细表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverLstVo));
        if(Objects.isNull(inLmtPrelistHandoverLstVo)){
            return null;
        }
        try {
            LmtPrelistHandoverLst lmtPrelistHandoverLst = new LmtPrelistHandoverLst();
            beanCopy(inLmtPrelistHandoverLstVo, lmtPrelistHandoverLst);
            lmtPrelistHandoverLst = lmtPrelistHandoverLstDao.queryLmtPrelistHandoverLstByPk(lmtPrelistHandoverLst);
            if (Objects.nonNull(lmtPrelistHandoverLst)) {
                LmtPrelistHandoverLstVO outLmtPrelistHandoverLstVo = beanCopy(lmtPrelistHandoverLst, new LmtPrelistHandoverLstVO());
                return outLmtPrelistHandoverLstVo;
            } else {
                logger.info("根据主键查询白名单移交明细表的记录为空！");
            }
        } catch (Exception e) {
            logger.error("根据主键查询白名单移交明细表记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public LmtPrelistHandoverLstVO querySingleLmtPrelistHandoverLstByCondition(LmtPrelistHandoverLstVO inLmtPrelistHandoverLstVo) {
        logger.info("根据条件查询单笔白名单移交明细表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverLstVo));
        if(Objects.isNull(inLmtPrelistHandoverLstVo)){
            return null;
        }
        try {
            LmtPrelistHandoverLst lmtPrelistHandoverLst = new LmtPrelistHandoverLst();
            beanCopy(inLmtPrelistHandoverLstVo, lmtPrelistHandoverLst);
            lmtPrelistHandoverLst = lmtPrelistHandoverLstDao.querySingleLmtPrelistHandoverLstByCondition(lmtPrelistHandoverLst);
            if (Objects.nonNull(lmtPrelistHandoverLst)) {
                LmtPrelistHandoverLstVO outLmtPrelistHandoverLstVo = beanCopy(lmtPrelistHandoverLst, new LmtPrelistHandoverLstVO());
                return outLmtPrelistHandoverLstVo;
            } else {
                logger.info("根据条件查询单笔白名单移交明细表的记录为空！");
            }
        } catch (Exception e) {
            logger.error("根据条件查询单笔白名单移交明细表记录发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistHandoverLstVO> queryLmtPrelistHandoverLstByCondition(LmtPrelistHandoverLstVO inLmtPrelistHandoverLstVo) {
        logger.info("条件查询白名单移交明细表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverLstVo));
        if(Objects.isNull(inLmtPrelistHandoverLstVo)){
            return null;
        }
        try {
            List<LmtPrelistHandoverLst> dataList = lmtPrelistHandoverLstDao.queryLmtPrelistHandoverLstByCondition(inLmtPrelistHandoverLstVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistHandoverLstVO> resultList = new ArrayList<LmtPrelistHandoverLstVO>();
                resultList = (List<LmtPrelistHandoverLstVO>) beansCopy(dataList, LmtPrelistHandoverLstVO.class);
                return resultList;
            } else {
                logger.info("条件查询白名单移交明细表的数据为空！");
            }
        } catch (Exception e) {
            logger.error("条件查询白名单移交明细表发生异常！", e);
        }
        return null;
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<LmtPrelistHandoverLstVO> queryLmtPrelistHandoverLstByConditionByPage(LmtPrelistHandoverLstVO inLmtPrelistHandoverLstVo) {
        logger.info("条件分页查询白名单移交明细表的请求参数为：" + JSONObject.toJSONString(inLmtPrelistHandoverLstVo));
        if(Objects.isNull(inLmtPrelistHandoverLstVo)){
            return null;
        }
        try {
            List<LmtPrelistHandoverLst> dataList = lmtPrelistHandoverLstDao.queryLmtPrelistHandoverLstByConditionByPage(inLmtPrelistHandoverLstVo);
            if (Objects.nonNull(dataList)) {
                List<LmtPrelistHandoverLstVO> resultList = new ArrayList<LmtPrelistHandoverLstVO>();
                resultList = (List<LmtPrelistHandoverLstVO>) beansCopy(dataList, LmtPrelistHandoverLstVO.class);
                pageSet(resultList, inLmtPrelistHandoverLstVo);
                return resultList;
            } else {
                logger.info("条件分页查询白名单移交明细表的数据为空！");
            }
        } catch (Exception e) {
            logger.error("条件分页查询白名单移交明细表发生异常！", e);
        }
        return null;
    }

	
	@Override
	public int inLmtPrelistHandoverLstList(List<LmtPrelistHandoverLstVO> lmtPrelistHandoverLstVos) {
		logger.info("条件分页查询白名单移交明细表的请求参数为：" + JSONObject.toJSONString(lmtPrelistHandoverLstVos));
		int count = -1;
		try {
			if(Objects.nonNull(lmtPrelistHandoverLstVos) && lmtPrelistHandoverLstVos.size() > 0){
				count = 0;
				for (LmtPrelistHandoverLstVO lmtPrelistHandoverLstVO : lmtPrelistHandoverLstVos) {
					LmtPrelistHandoverLst lmtPrelistHandoverLst = new LmtPrelistHandoverLst();
					beanCopy(lmtPrelistHandoverLstVO, lmtPrelistHandoverLst);
		            count = lmtPrelistHandoverLstDao.insertLmtPrelistHandoverLst(lmtPrelistHandoverLst) + count;
				}
			}else {
                logger.info("新增查询白名单移交明细表的数据为空！");
            }
		} catch (Exception e) {
			logger.error("新增白名单移交明细表出错", e);
		}
		return count;
	}
}